local ClientOHOH = _G.ClientOHOH;

local M = ClientOHOH.class.new(script, ClientOHOH.files.OHOHOLYBUIBase());
local CallBackManager = ClientOHOH.load.CallBackManager();
local BtnHelper = ClientOHOH.load.BtnHelper();
local LanguageHelper=_G.LanguageHelper 
local BigNumberHelper = ClientOHOH.load.BigNumberHelper();

local CommonOHOH =_G.CommonOHOH


function InitInsts(ui)
	ui.insts = {};

    ui.insts={
        title1="ctrl.Level.text1",
        title2="ctrl.Level.text2",
        title3="ctrl.Level.text3",
        Bg="ctrl.Bg",
        lockCondition={
            root="ctrl.condition.root",
            title="ctrl.condition.text1",
            con1="ctrl.condition.text2",
            con2="ctrl.condition.text3",
        },

        unlock={
            root="ctrl.unlock.root",
            cost="ctrl.unlock.cost",
            icon="ctrl.unlock.icon",
            btn="ctrl.unlock.btn",
        },
        teleport={
            root="ctrl.teleport.root",
            text="ctrl.teleport.text",
            btn="ctrl.teleport.btn",
        },


    }

end

function M.new(...)
	return M(...);
end;


function M.ctor(self,ui,data,image)
	InitInsts(self)
	
	M.super.ctor(self, ui);

    self.insts.Bg.Image=image
    --填充静态信息
    self.insts.title1.Text=data.title1
    self.insts.title2.Text=data.title2
    self.insts.title3.Text=data.title3
   
    self.insts.lockCondition.con1.Text=data.lockTip[1]
    self.insts.lockCondition.con2.Text=data.lockTip[2]
    self.insts.lockCondition.title.Text=_G.LanguageHelper:GetText(888011)
    self.insts.teleport.text.Text="Teleport"


    self.data=data

    for k,v in pairs(data.unlockCost) do
        self.insts.unlock.cost.Text=BigNumberHelper:ToString(v)
        local icon=_G.CommonOHOH.load.ItemTool().GetItemShowView(k)
        self.insts.unlock.icon.Image=icon
    end
    --解锁
    CallBackManager:AddRbxConnect(self,self.insts.unlock.btn.Activated, function()
            self.data.unlockEvent:Action(self.data)
	end);

    CallBackManager:AddRbxConnect(self,self.insts.teleport.btn.Activated, function()
            self.data.teleportEvent:Action(self.data)
    end);

    self.data.updEvent:Connect(function()
        self:Update()
    end)
    self:Update()
end;

--更新状态
function M.Update(self)	
    if self.data.isCanTeleport then
        self.insts.teleport.root.Visible=true
        self.insts.unlock.root.Visible=false
    else
        self.insts.teleport.root.Visible=false
        self.insts.unlock.root.Visible=true
    end


    if self.data.isCanUnlock then
        self.insts.lockCondition.root.Visible=false
       
    else
        self.insts.lockCondition.root.Visible=true
    end

    self.insts.lockCondition.con1.Text=self.data.lockTip[1]
    self.insts.lockCondition.con2.Text=self.data.lockTip[2]

end

function M.dtor(self)
	M.super.dtor(self);
end;



return M
